package com.mes.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mes.entity.Message;
import com.mes.entity.MessageLog;
import com.yy.base.common.dao.Dao;
import com.yy.base.util.ObjectUtil;

@Service
@SuppressWarnings("unchecked")
public class MessageService {
	@Autowired
	private Dao dao;
	public List<Message> getMessageList() {
		String sql = "select ul.address phone, m.title, m.text, ul.receive_user_id userId, m.Emes_Message_id messageId, m.created " +
        "select m.title, m.text, m.url, m.emes_message_id, m.created" +
        "  from Emes_Message m, Emes_Message_User_Log ul" +
        " where m.emes_message_id = ul.emes_message_id" +
        "   and ul.send_mode = 'MESSAGE'" +
        "   and m.created >= trunc(sysdate) - 3" +//查询最近3天的数据，之前数据过滤掉
        "   and nvl(ul.status, 'CREATE') = 'CREATE'" +
        " order by m.created desc";
		List list = dao.query(sql);
		return ObjectUtil.listMapToEntity(Message.class, list);
	}
	
	public int addMessageLog(MessageLog log) {
		String sql = "update Emes_Message_User_Log set log_time = sysdate, status = 'OK' " +
				"where Emes_Message_id = ? and receive_user_id = ? ";
		return dao.executeSql(sql, log.getMessageId(), log.getUserId());
	}
}